define(['text!service/addAppliances.html'],
	function(viewTemplate) {
		return Piece.View.extend({
			id: 'service_addAppliances',

			events: {
				"click #submit": "submit",
				"click #submit2": "submit2",
			},
			render: function() {
				$(this.el).html(viewTemplate);

				Piece.View.prototype.render.call(this);
				return this;
			},
			onShow: function() {

				var windowHeight = $(window).height();
				var elTop = $("#addAppliances").offset().top;
				var elHeight = windowHeight - elTop;

				console.info(elHeight);
				$("#addAppliances").css({
					"height": elHeight
				});
				new iScroll($("#addAppliances")[0]);
				// $("#warrantyCard")[0].css("bottom", "20px");



				// $("#warrantyCard")[0].refresh();

			},
			submit: function() {


				// this.container.navigateForResult('/service/warrantyCard2', {
				// 	trigger: true
				// }, 'service/addAppliances', this.onGotResult);
			},

			submit2: function() {

				// var recommend = document.getElementById("img2");
				// recommend.style.display = 'block';


				this.editUserImg();

			},



			editUserImg: function() {
				var me = this;
				var dialog = new Piece.Dialog({
					autoshow: true,
					target: 'body',
					title: '请选择',
					content: ''
				}, {
					configs: [{
						title: "手机拍照",
						eventName: 'camera'
					}, {
						title: "手机相册",
						eventName: 'library'
					}],
					camera: function() {
						console.log("调用相册");
						cordova.exec(function(data) {

							console.info(data);

							$('#img2').attr("src", data);

						}, function(err) {

						}, "Camera", "takePicture", [80, 1, 1, 100, 100, 1, 0, false, true, true]);
						// dialog.hide();
					},
					library: function() {
						console.log("调用相册");
						cordova.exec(function(data) {

							console.info(data);

							$('#img2').attr("src", data);

						}, function(err) {

						}, "Camera", "takePicture", [80, 1, 0, 100, 100, 1, 0, false, true, true]);
						// dialog.hide();
					}

				});
				$('.cube-dialog-screen').click(function() {
					dialog.hide();
				});
				// private static final int DATA_URL = 0;              // Return base64 encoded string
				// private static final int FILE_URI = 1;              // Return file uri (content://media/external/images/media/2 for Android)
				// private static final int NATIVE_URI = 2;			// On Android, this is the same as FILE_URI

				// private static final int PHOTOLIBRARY = 0;          // Choose image from picture library (same as SAVEDPHOTOALBUM for Android)
				// private static final int CAMERA = 1;                // Take picture from camera
				// private static final int SAVEDPHOTOALBUM = 2;       // Choose image from picture library (same as PHOTOLIBRARY for Android)

				// private static final int PICTURE = 0;               // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
				// private static final int VIDEO = 1;                 // allow selection of video only, ONLY RETURNS URL
				// private static final int ALLMEDIA = 2;              // allow selection from all media types

				// private static final int JPEG = 0;                  // Take a picture of type JPEG
				// private static final int PNG = 1;                   // Take a picture of type PNG
				// private static final String GET_PICTURE = "Get Picture";
				// private static final String GET_VIDEO = "Get Video";
				// private static final String GET_All = "Get All";

				// private static final String LOG_TAG = "CameraLauncher";

				// private int mQuality;                   // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
				// private int targetWidth;                // desired width of the image
				// private int targetHeight;               // desired height of the image
				// private Uri imageUri;                   // Uri of captured image
				// private int encodingType;               // Type of encoding to use
				// private int mediaType;                  // What type of media to retrieve
				//private boolean saveToPhotoAlbum; // Should the picture be saved to the device's photo album
				//private boolean correctOrientation; // Should the pictures orientation be corrected
				//private boolean allowEdit;              // Should we allow the user to crop the image. UNUSED.
				// this.mQuality = args.getInt(0);
				//         destType = args.getInt(1);
				//         srcType = args.getInt(2);
				//         this.targetWidth = args.getInt(3);
				//         this.targetHeight = args.getInt(4);
				//         this.encodingType = args.getInt(5);
				//         this.mediaType = args.getInt(6);
				//         //this.allowEdit = args.getBoolean(7); // This field is unused.
				//         this.correctOrientation = args.getBoolean(8);
				//         this.saveToPhotoAlbum = args.getBoolean(9);

				// var exec = cordova.require('cordova/exec');



			},

		}); //view define

	});